﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Willow.IService.Auth;
using Willow.Model;
using Willow.MVC.Result;
namespace Willow.WebApplication.Areas.Auth.Controllers
{
    public class ActionController : Controller
    {

        #region 属性

        public IActionService ActionService { get; set; }
        public IModuleActionService ModuleActionService { get; set; }
        
        #endregion

        #region 页面

        #endregion

        #region 操作

        /// <summary>
        /// 获取功能分页后信息
        /// </summary>
        /// <param name="moduleId">The module identifier.</param>
        /// <param name="page">The page.</param>
        /// <param name="rows">The rows.</param>
        /// <returns></returns>
        public JsonResult GetPagedList(Guid moduleId, int page = 1, int rows = 10)
        {
            int total = 0;
            var lstData = ModuleActionService
            .Filter(p => p.ModuleId == moduleId && p.Auth_Module.IsDelete == false && p.Auth_Action.IsDelete == false)
            .OrderBy(p => p.Auth_Action.DisplayOrder)
            .Select(p => new
            {
                p.Auth_Action.Name,
                p.Auth_Action.Handle,
                p.Auth_Action.Id,
                p.Auth_Action.DisplayOrder,
                p.Auth_Action.IsDelete,
                p.Auth_Action.Icon,
                p.Auth_Action.Category
            });
            return Json(new { rows = lstData, total }, JsonRequestBehavior.AllowGet);
        }

        /// <summary>
        /// 提交功能信息
        /// </summary>
        /// <param name="lstInsert">The LST insert.</param>
        /// <param name="lstDelete">The LST delete.</param>
        /// <param name="lstUpdate">The LST update.</param>
        /// <param name="moduleId">The module identifier.</param>
        /// <returns></returns>
        public JsonResult Submit(List<Auth_Action> lstInsert, List<Auth_Action> lstDelete, List<Auth_Action> lstUpdate, Guid moduleId)
        {
            return this.StandardJson(() =>
            {
                ActionService.Submit(lstInsert, lstDelete, lstUpdate, moduleId);
            });
        }

        #endregion

    }
}